package com.idanchuang.component.sentinel.config;

import java.util.Arrays;

/**
 * @author yjy
 * @date 2020/3/31 16:57
 **/
public class SentinelConfigBean {

    /**
     * 自定义限流信息 attributeKey
     */
    public static final String SENTINEL_MSG_KEY = "sentinelMsg";

    /** 是否接入sentinel功能 */
    private boolean enabled = true;
    /** 是否打开流控总开关 */
    private boolean switchOn = true;
    /** 是否延迟初始化 */
    private boolean lazyInit = false;
    /** 指定应用的名称 */
    private String projectName = System.currentTimeMillis() + "";
    /** 指定应用的类型 0:普通应用 1:gateway网关 */
    private int appType = 0;
    /** 单个监控日志文件的大小, 单位: 字节 */
    private int metricFileSingleSize = 52428800;
    /** 监控日志文件的总数上限 */
    private int metricFileTotalCount = 10;
    /** 最大的有效响应时长（ms），超出此值则按照此值记录 */
    private int statisticMaxRt = 4900;
    /** SPI 加载时使用的 ClassLoader，默认为给定类的 ClassLoader */
    private String spiClassloader = "default";
    /** Sentinel 日志文件目录 */
    private String logDir = "/data/logs/csp";
    /** 日志文件名中是否加入进程号，用于单机部署多个应用的情况 */
    private boolean logUsePid = false;
    /** Record 日志输出的类型，file 代表输出至文件，console 代表输出至终端 */
    private String logOutputType = "file";
    /** 控制台的地址，指定控制台后客户端会自动向该地址发送心跳包。地址格式为：hostIp:port */
    private String dashboardServer = "localhost:10110";
    /** 心跳包发送周期，单位毫秒 */
    private int heartbeatIntervalMs = 30000;
    /** 本地启动 HTTP API Server 的端口号 */
    private Integer apiPort = null;
    /** 指定心跳包中本机的 IP */
    private String heartbeatClientIp = null;
    /** 资源名中是否需要携带请求方法类型 */
    private boolean httpMethodSpecify = true;
    /** 获取origin时, 优先获取链路入口信息 {@link com.idanchuang.component.core.helper.EnvContext#getAttribute(Dc.ORIGIN_REQUEST)} */
    private boolean preferOriginReq = false;
    /** 如何定义一个请求的来源, 默认是HEADER中的"Origin" */
    private String originParser = "Origin";
    /** 从哪里取请求来源信息?  header / query */
    private String originParseFrom = "Header";
    /** 适用动态流控的接口 (默认所有) */
    private String[] includePathPatterns = {"/**"};
    /** 规避动态限流的接口 (默认不规避) */
    private String[] excludePathPatterns = {};
    /** 拒绝访问后返回的 HTTP CODE */
    private int responseCode = 429;

    public String getProjectName() {
        return projectName;
    }

    public String getOriginParseFrom() {
        return originParseFrom;
    }

    public void setOriginParseFrom(String originParseFrom) {
        this.originParseFrom = originParseFrom;
    }

    public void setProjectName(String projectName) {
        this.projectName = projectName;
    }

    public int getAppType() {
        return appType;
    }

    public String getOriginParser() {
        return originParser;
    }

    public void setOriginParser(String originParser) {
        this.originParser = originParser;
    }

    public String[] getIncludePathPatterns() {
        return includePathPatterns;
    }

    public boolean isPreferOriginReq() {
        return preferOriginReq;
    }

    public void setPreferOriginReq(boolean preferOriginReq) {
        this.preferOriginReq = preferOriginReq;
    }

    public boolean isSwitchOn() {
        return switchOn;
    }

    public void setSwitchOn(boolean switchOn) {
        this.switchOn = switchOn;
    }

    public void setIncludePathPatterns(String[] includePathPatterns) {
        this.includePathPatterns = includePathPatterns;
    }

    public boolean isHttpMethodSpecify() {
        return httpMethodSpecify;
    }

    public void setHttpMethodSpecify(boolean httpMethodSpecify) {
        this.httpMethodSpecify = httpMethodSpecify;
    }

    public String[] getExcludePathPatterns() {
        return excludePathPatterns;
    }

    public void setExcludePathPatterns(String[] excludePathPatterns) {
        this.excludePathPatterns = excludePathPatterns;
    }

    public void setAppType(int appType) {
        this.appType = appType;
    }

    public int getMetricFileSingleSize() {
        return metricFileSingleSize;
    }

    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public void setMetricFileSingleSize(int metricFileSingleSize) {
        this.metricFileSingleSize = metricFileSingleSize;
    }

    public int getMetricFileTotalCount() {
        return metricFileTotalCount;
    }

    public void setMetricFileTotalCount(int metricFileTotalCount) {
        this.metricFileTotalCount = metricFileTotalCount;
    }

    public int getStatisticMaxRt() {
        return statisticMaxRt;
    }

    public void setStatisticMaxRt(int statisticMaxRt) {
        this.statisticMaxRt = statisticMaxRt;
    }

    public boolean isLazyInit() {
        return lazyInit;
    }

    public void setLazyInit(boolean lazyInit) {
        this.lazyInit = lazyInit;
    }

    public String getSpiClassloader() {
        return spiClassloader;
    }

    public void setSpiClassloader(String spiClassloader) {
        this.spiClassloader = spiClassloader;
    }

    public String getLogDir() {
        return logDir;
    }

    public void setLogDir(String logDir) {
        this.logDir = logDir;
    }

    public boolean isLogUsePid() {
        return logUsePid;
    }

    public void setLogUsePid(boolean logUsePid) {
        this.logUsePid = logUsePid;
    }

    public String getLogOutputType() {
        return logOutputType;
    }

    public void setLogOutputType(String logOutputType) {
        this.logOutputType = logOutputType;
    }

    public String getDashboardServer() {
        return dashboardServer;
    }

    public void setDashboardServer(String dashboardServer) {
        this.dashboardServer = dashboardServer;
    }

    public int getHeartbeatIntervalMs() {
        return heartbeatIntervalMs;
    }

    public void setHeartbeatIntervalMs(int heartbeatIntervalMs) {
        this.heartbeatIntervalMs = heartbeatIntervalMs;
    }

    public Integer getApiPort() {
        return apiPort;
    }

    public void setApiPort(Integer apiPort) {
        this.apiPort = apiPort;
    }

    public String getHeartbeatClientIp() {
        return heartbeatClientIp;
    }

    public void setHeartbeatClientIp(String heartbeatClientIp) {
        this.heartbeatClientIp = heartbeatClientIp;
    }

    public int getResponseCode() {
        return responseCode;
    }

    public void setResponseCode(int responseCode) {
        this.responseCode = responseCode;
    }


    @Override
    public String toString() {
        return "SentinelConfigBean{" +
                "enabled=" + enabled +
                ", switchOn=" + switchOn +
                ", lazyInit=" + lazyInit +
                ", projectName='" + projectName + '\'' +
                ", appType=" + appType +
                ", metricFileSingleSize=" + metricFileSingleSize +
                ", metricFileTotalCount=" + metricFileTotalCount +
                ", statisticMaxRt=" + statisticMaxRt +
                ", spiClassloader='" + spiClassloader + '\'' +
                ", logDir='" + logDir + '\'' +
                ", logUsePid=" + logUsePid +
                ", logOutputType='" + logOutputType + '\'' +
                ", dashboardServer='" + dashboardServer + '\'' +
                ", heartbeatIntervalMs=" + heartbeatIntervalMs +
                ", apiPort=" + apiPort +
                ", heartbeatClientIp='" + heartbeatClientIp + '\'' +
                ", httpMethodSpecify=" + httpMethodSpecify +
                ", originParser='" + originParser + '\'' +
                ", originParseFrom='" + originParseFrom + '\'' +
                ", includePathPatterns=" + Arrays.toString(includePathPatterns) +
                ", excludePathPatterns=" + Arrays.toString(excludePathPatterns) +
                ", responseCode=" + responseCode +
                '}';
    }
}
